//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2007
//
// Delete object.
//

# include "StdAfx.h"
# include "UndoRedo.h"
# include "Map.h"
# include "DeleteObject.h"
# include "Label.h"
# include "Selection.h"
# include "Globals.h"

class CDeleteObjectAction : public CEditAction {
  public:
	CDeleteObjectAction (rgn_t * _pRgn) : m_pRgn (_pRgn) {}

	virtual void GetName (string_t & _str) const;
	virtual cu_t CanUndo () const {return cuYes;}
	virtual bool Do ();
	virtual void Undo ();
	virtual void Redo ();

  private:
	rgn_t * const m_pRgn;
};

void CDeleteObjectAction::GetName (string_t & _str) const {
	CCritSec::CLock lock (g_cs);

	assert (m_pRgn);
	_str.append ("delete [");
	GetHintText (* m_pRgn, _str);
	_str.append ("]");
}

bool CDeleteObjectAction::Do () {
	CCritSec::CLock lock (g_cs);

	m_pRgn->Delete (g_map, true);

	return true;
}

void CDeleteObjectAction::Undo () {
	CCritSec::CLock lock (g_cs);

	m_pRgn->Undelete (g_map, true);
}

void CDeleteObjectAction::Redo () {
	CDeleteObjectAction::Do ();
}

////////////////////////////////////////////////////////

void DeleteObject (rgn_t * _pRgn) {
	PerformEditAction (new CDeleteObjectAction (_pRgn));
}

